package com.jk.service.Impl;

import com.jk.pojo.PostBean;
import com.jk.pojo.UserBean;
import com.jk.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 2 * @author lujintao
 * 3 * @description 类描述
 * 4 * @date 2021/11/16
 * 5 * @version </pre>
 * 6
 */
@Service
public class MyServiceImpl implements MyService {
    @Autowired
    private RestTemplate restTemplate;
    @Override
    public String text() {
        return restTemplate.getForObject("http://provider/log/text",String.class);
    }

    @Override
    public Map<String, String> loginUser(UserBean q) {
        Map<String, Object> map = new HashMap<>();
       if (q.getName()!=null && q.getName()!=""){
            map.put("name",q.getName());
       }
        if (q.getPassword()!=null && q.getPassword()!=""){
            map.put("password",q.getPassword());
        }

        return restTemplate.getForObject("http://provider/log/loginUser?name={name}&password={password}",Map.class,map);
    }

    @Override
    public UserBean SessUser(String name) {
        return restTemplate.getForObject("http://provider/log/SessUser?name={name}",UserBean.class,name);
    }

    @Override
    public void addUser(UserBean w) {
        restTemplate.postForLocation("http://provider/log/addUser",w);
    }

    @Override
    public List<UserBean> selectAdmin() {
        return restTemplate.getForObject("http://provider/log/selectAdmin",List.class);
    }

    @Override
    public List<PostBean> selectPort() {
        return restTemplate.getForObject("http://provider/log/selectPort",List.class);
    }

    @Override
    public void addPost(PostBean e) {
        restTemplate.postForLocation("http://provider/log/addPost",e);
    }
}
